import React from 'react';
import { BrowserRouter as Router, Route, Link, Redirect } from "react-router-dom";
import '../css/login.css';
import { observer } from 'mobx-react';
import { Card } from 'antd';
import 'antd/lib/message/style'
import 'antd/lib/list/style'
import 'antd/lib/card/style'
import 'antd/lib/input/style'
import PostService from '../service/post'

@observer
export default class Post extends React.Component {
    constructor(props) {
        super(props);
        this.service = new PostService(); //若不写，则会导致问题
        let [, , id] = (props.location.pathname).split('/');
        if  (id){ 
           this.service.get(id); //进行强制int如若为None,则
        }
        else  
            this.service.get(2)
    }
    render() {
        const { post_title, author_id, post_name, date, post_conent } = this.service.post;
        return <div>
            <Card title={post_title} bordered={true} style={{ width: 1000 }}>
                <p>作者{post_name}   日期 {String(date).replace('T',' ')} </p>
                <p>文章内容 {post_conent}</p>
            </Card>
        </div>
    }
}


